﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

using Weazel.Badger.Vhdl.Types;

namespace Weazel.Badger.Vhdl.Expressions
{
  public class EnumerationMemberReferenceExpression : Expression
  {
    private LitteralBasedEnumerationType enumType;
    private string member;

    public EnumerationMemberReferenceExpression(
			IComponent parentContainer,
			LitteralBasedEnumerationType enumType, 
			string member
		) : base(parentContainer, enumType, null)
    {
      this.enumType = enumType;
      this.member = member;

      System.Diagnostics.Debug.Assert(enumType.ContainsMember(member));
    }

    public override bool VerifyType(ref List<VerifyMessage> messages)
    {
      if (this.Type == Types.Types.Undefined)
        return false;

      if (this.Type != enumType)
      {
        messages.Add(new VerifyMessage("Wrong type set for enumeration member expression."));
        return false;
      }

      return true;
    }

    public override TypeSet GetPossibleTypes()
    {
      return new TypeSet(enumType);
    }

		public override void SetActualType(Entity entity, Process process, Statements.StatementCollection statements, Vhdl.Types.Type type)
    {      
      System.Diagnostics.Debug.Assert(type == enumType);

      this.Type = type;
    }

    public override string ToString()
    {
      return member;
    }
  }
}
